package com.treasure.web.mapstruct;

import com.treasure.common.enums.TrainingStatEnum;
import com.treasure.infrastructure.model.po.KnowledgeDocument;
import com.treasure.web.command.response.KnowledgeDocumentResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.Optional;

/**
 * @author sunhongmin
 * @date 2023/9/4 14:25
 * @description
 */
@Mapper
public interface KnowledgeDocumentAssembler {
    KnowledgeDocumentAssembler INSTANCE = Mappers.getMapper(KnowledgeDocumentAssembler.class);

    @Mapping(source = "trainingStat", target = "trainingStat", qualifiedByName = "convertStatusDesc")
    KnowledgeDocumentResponse convertToKnowledgeDocumentResponse(KnowledgeDocument knowledgeDocument);

    @Named("convertStatusDesc")
    default String convertStatusDesc(String trainingStat) {
        TrainingStatEnum instance = TrainingStatEnum.getInstance(trainingStat);
        return Optional.ofNullable(instance).map(TrainingStatEnum::getValue).orElse("未知状态，" + trainingStat);
    }
}
